# $LastChangedDate: 2013-12-31 17:13:45 -0500 (Tue, 31 Dec 2013) $
# LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
# Find FLTK (Fast-and-Light GUI Toolkit).
# Output:
# FLTK_FOUND
# FLTK_INC_DIR
# FLTK_LIBS
#-------------------------------------------------------------------------------

INCLUDE( CMakeModules/inc_find.cmake )

#-------------------------------------------------------------------------------
# Find include directory : FLTK_INC_DIR

FIND_PATH( FLTK_INC_DIR
    # FreeBSD 10: /usr/local/include/FL/Fl.H
    # Debian 7: /usr/include/Fl/Fl.H
    NAMES Fl/Fl.H Fl/Fl.h FL/Fl.h FL/Fl.H
    PATHS ${POSSIBLE_INC_DIRS}
          $ENV{FLTK_DIR}/include
          $ENV{FLTK_DIR}
          $ENV{ProgramFiles}/FLTK/include
          c:/apps/FLTK/include  # Windows Vista prevents installing in Program Files
)

#-------------------------------------------------------------------------------
# Find libraries : FLTK_LIBS
# FLTK has multiple libraries.
# This cmake file will try to find the required ones
# and catenate them into the string FLTK_LIBS.

# Find one FLTK lib.
MACRO( FIND_FLTK_LIB VAR_NAME LIB_NAME )
    FIND_LIBRARY( ${VAR_NAME}
        NAMES ${LIB_NAME}
        PATHS ${POSSIBLE_LIB_DIRS}
              $ENV{FLTK_DIR}/lib
              $ENV{FLTK_DIR}
              $ENV{ProgramFiles}/FLTK/lib
              c:/apps/FLTK/lib  # Windows Vista prevents installing in Program Files
    )
ENDMACRO()

FIND_FLTK_LIB( FLTK_LIB        fltk        )
FIND_FLTK_LIB( FLTK_LIB_FORMS  fltk_forms  )
FIND_FLTK_LIB( FLTK_LIB_IMAGES fltk_images )
FIND_FLTK_LIB( FLTK_LIB_JPEG   fltk_jpeg   )   # FLTK's cmake has to build on Windows but omits them on Linux
FIND_FLTK_LIB( FLTK_LIB_PNG    fltk_png    )   # FLTK's cmake has to build on Windows but omits them on Linux

#-------------------------------------------------------------------------------
# Found everything?
# NOTE: Be careful with FLTK_LIB/FLTK_LIBS (singular/plural).

IF( FLTK_INC_DIR AND FLTK_LIB )
    SET( FLTK_FOUND "TRUE" )
    MESSAGE( STATUS "Found FLTK: ${FLTK_LIB}" )

    # Assign FLTK_LIBS (plural).
    SET( FLTK_LIBS ${FLTK_LIB} ${FLTK_LIB_FORMS} ${FLTK_LIB_IMAGES} )
    IF( FLTK_LIB_JPEG )  # else equals "*_NOT_FOUND" rather than empty
        SET( FLTK_LIBS ${FLTK_LIBS} ${FLTK_LIB_JPEG} )
    ENDIF()
    IF( FLTK_LIB_PNG )  # else equals "*_NOT_FOUND" rather than empty
        SET( FLTK_LIBS ${FLTK_LIBS} ${FLTK_LIB_PNG} )
    ENDIF()

    # Apply.
    ADD_SYSTEM_INCLUDE_DIR( ${FLTK_INC_DIR} )
ELSE()
    IF( FLKT_FIND_REQUIRED )
        MESSAGE( FATAL_ERROR "Could not find FLTK" )
    ENDIF()
ENDIF()
